using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using UMC.Data;
using UMC.Web;

namespace UMC.WorkFlow.Subassembly
{
    /// <summary>
    /// 
    /// </summary>
    [Apiumc("WorkFlow", "TextSetting", Auth = WebAuthType.Admin, Desc = "文本配置")]
    public class TextSettinggDesign : DesignActivity
    {
        protected override object SetValue(PropertyInfo property, object value, DesignAttribute attr)
        {
            var sett = value as TextSetting ?? new TextSetting();
            var v = this.AsyncDialog("TextSetting", g =>
            {
                var form = new UIFormDialog() { Title = attr.Caption };
                form.AddCheckBox("事件", "CommandType", "0")//.Put("保存", "1", (sett.CommandType & CommandType.Save) > 0)
                .Put("申请", "2", (sett.CommandType & CommandType.Submit) > 0)
                .Put("驳回", "4", (sett.CommandType & CommandType.Reject) > 0)
                .Put("挂起", "8", (sett.CommandType & CommandType.Lock) > 0)
                .Put("通过", "16", (sett.CommandType & CommandType.Approval) > 0)
                .Put("加签", "64", (sett.CommandType & CommandType.Apostille) > 0)
                .Put("终止", "32", (sett.CommandType & CommandType.Terminate) > 0)
                .Put("完结", "512", (((int)sett.CommandType) & 512) > 0);
                form.AddTextarea("内容", "Text", sett.Text).NotRequired();
                form.Submit("确认",   "WorkFlow.Design");
                if (String.IsNullOrEmpty(attr.Explain) == false)
                {
                    form.AddFooter(attr.Explain);
                    //var desc = new UMC.Web.UI.UIDesc(attr.Explain);
                    //desc.Style.Color(0x999).Size(12);
                    //form.Add(desc);
                }
                return form;
            });
            sett.CommandType = CommandType.Undefine; 
            var vs = v["CommandType"].Split(',');
            foreach (var c in vs)
            {
                sett.CommandType = sett.CommandType | (CommandType)UMC.Data.Utility.EnumParse(c, CommandType.Undefine);
            }
            sett.Text = v["Text"] ?? String.Empty;
            if (String.Equals("none", sett.Text, StringComparison.CurrentCultureIgnoreCase))
            {
                sett.Text = String.Empty;
            }
            return sett;

        }
    }
}
